<script type="text/javascript">
var index{$name};
//单图
function uploadSingle{$name}(event){
	layui.use(['upload','laytpl'], function(){
		var upload = layui.upload,laytpl = layui.laytpl;
		var tpl_html = $("#image_html{$name}").html();
		laytpl(tpl_html).render([], function(html){
			//单图上传框
			index{$name} = layer.open({
		  		  type: 1,
		  		  title: "本地上传",
		  		  area: ['550px'], //宽高
		  		  content:  html,
		  		  cancel: function(){
		  		    //右上角关闭回调
					$('#singleUploadImage{$name} .layui-upload-list').empty();
		  		    //return false 开启该代码可禁止点击该按钮关闭
		  		  },
			      success: function(layero, index){
					  var mask = $(".layui-layer-shade");
					     mask.appendTo(layero.parent());
					     
					   	//普通图片上传
					 	var uploadInst = upload.render({
						    elem: '#single{$name}'
						    ,url: '{:addon_url("File://common/File/image")}'
						    ,auto: false
						    ,data: {'thumb_type' : "{$thumb_type}"}
						    ,multiple: false
							,bindAction: '#btnSingle{$name}'
						    ,choose: function(obj){
								  //预读本地文件示例，不支持ie8
								  obj.preview(function(index, file, result){
						                s = '<div class="nc-upload-wrap"><img class="layui-upload-img" style="max-width: 100%;max-height: 100%;" src="'+result+'"></div>';
						                $('#singleUploadImage{$name} .layui-upload-list').html(s);
								  });
								  $(".nc-upload-img .add-style").text("点击修改图片");
						    }
						    ,done: function(res, index, upload){
					    		if(res.code ==  0){
					    			$('#singleUploadImage{$name} .layui-upload-list').empty();
									try{
										singleImageUploadSuccess(res.data,"{$name}");
										loadImgMagnify();
									}catch(e){
										console.error("缺少回调函数singleImageUploadSuccess()",e.message);
									}
									layer.close(index{$name});
					    	    }
						    }
						    //如果上传失败
						    ,error: function(index, upload){

						    }
					  	});
				  }
			});
		});
	});
	
}
/**
 * 网络图盘提取
 */
function  fetchPubImg{$name}(){
    var fetch_image_path = $("input[name=fetch_image_path{$name}]").val();

    $.ajax({
        type : "post",
        async : false,
        url : '{:addon_url("File://common/File/fetchPubImg")}',
        data : {
            fetch_image_path : fetch_image_path
        },
        dataType : "JSON",
        success : function(data) {
        	if(data['code'] != 0){
        		layer.msg(data['message']);
        		return false;
        	}else{
        		try{
        			imageSuccess{$name}(data.data);
                    $(".{$name}").html('<div class="upload-img-box has-choose-image"><div><img src="'+nc.img(data.data)+'"><i class="del">x</i></div></div>');
                    $("input[name='{$name}']").val(data.data);
        			singleImageUploadSuccess(data.data,"{$name}");
					loadImgMagnify();
        		}catch(e){
        			console.error("缺少回调函数singleImageUploadSuccess()");
        		}
        		layer.close(index{$name});
        	}
        }
    });

}

</script>
<!-- 单图上传开始 -->

<script type="text/html" id="image_html{$name}">

<div class="layui-form" id="singleUploadImage{$name}" style="margin-top: 15px!important;font-size:12px;">
  <div class="layui-form-item">
	    <label class="layui-form-label sm">网络图片</label>

	    <div class="layui-input-inline">
	       <input type="text" name="fetch_image_path{$name}" placeholder="请添加网络图片地址"  id="web_image{$name}" class="layui-input nc-len-mid">
	    </div>
	    <button type="button" class="layui-btn layui-btn-primary" onclick="fetchPubImg{$name}();">提取</button>
  </div>
  <div class="layui-form-item" style="height:130px">
	    <label class="layui-form-label sm">本地图片</label>
	    <div class="layui-input-block" >
			<div class="layui-upload-list"></div>
			<div class="nc-upload-img" id="single{$name}" title="仅支持 gif、 jpeg、 png、 bmp 4种格式, 大小不超过3.0 MB">
				<span class="add-img">+</span>
				<p class="add-style">点击添加图片</p>
			</div>
		</div>
  </div>

  <div class="nc-form-row sm">
	   <button type="button" class="layui-btn" id="btnSingle{$name}">保存</button>
	   <button class="layui-btn layui-btn-primary" onclick="back()">返回</button>
  </div>
</div>
</script>
<!-- 单图上传结束 -->